package Cards;

import java.sql.SQLOutput;
import java.util.ArrayList;
import java.util.Random;

public class CardDemo {
    //准备52张牌
    ArrayList<card> cards = new ArrayList<>(52);
    private String [] suits = {"♣","♦","♠","♥"};

    public void buyCard(){
        for (int i = 1; i <=13 ; i++) {
            for (int j = 0; j <suits.length ; j++) {
                card c = new card(suits[j],i );
                cards.add(c);
            }
        }
    }
    public void display(){
        for(int i = 0; i < cards.size();i++){
            System.out.print(cards.get(i));
        }
        System.out.println();
    }
    //这里洗牌采用选取 52个随机数 随机交换52次
    private void swap(int x,int y){
        card temp  =  cards.get(x);
        cards.set(x,cards.get(y));
        cards.set(y,temp);
    }
    public void shuffle(){
        Random random = new Random();
        for(int i = 0;i<cards.size();i++){
            int c = random.nextInt(52);
            swap(i,c);
        }
    }
    // 三个人随机分牌 五张
    // 我们采用数组存放 三个人这样便于确定牌放在那个人手里
    public ArrayList<ArrayList<card>> distribute(){
        ArrayList<ArrayList<card>> hands = new ArrayList<>();
        hands.add(new ArrayList<>());
        hands.add(new ArrayList<>());
        hands.add(new ArrayList<>());
        int count = 0;
        for (int i = 0; i < 5; i++) {
            for (int j = 0; j < 3; j++) {
                hands.get(j).add(cards.remove(count++));
            }
        }
        return hands;
    }
}
